package graph;

import zagaynov.CoagulationFactor;
import zagaynov.ModelType;
import zagaynov.Properties;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class RG {
    private JSpinner equationNumber;
    private JSpinner integrationStepSize;
    private JSpinner initialTimeValue;
    private JSpinner finalTimeValue;
    private JSpinner timeStepSize;
    private JSpinner sourcePower;
    private JButton calculateButton;
    public JPanel rootField;
    private JComboBox modelType;
    private JComboBox coagulationFactor;

    public RG(final ZagaynovGUI zagaynovGUI) {
        initGUI();
        calculateButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Properties p = new Properties();
                p.setEquationsNumber((Integer)equationNumber.getValue());
                p.setFinalTimeValue((Integer) finalTimeValue.getValue());
                p.setInitialTimeValue((Integer) initialTimeValue.getValue());
                p.setIntegrationStepSize((Double) integrationStepSize.getValue());
                p.setTimeStepSize((Double) timeStepSize.getValue());
                p.setSourcePower((Double) sourcePower.getValue());
                p.setModelType((ModelType)modelType.getSelectedItem());
                p.setCoagulationFactor((CoagulationFactor)coagulationFactor.getSelectedItem());
                zagaynovGUI.calculate(p);
            }
        });
    }

    private void initGUI() {
        equationNumber.setModel(new SpinnerNumberModel(10,1,500,1));
        integrationStepSize.setModel(new SpinnerNumberModel(0.01, 0.001, 1, 0.001));
        initialTimeValue.setModel(new SpinnerNumberModel(0,0,500,1));
        finalTimeValue.setModel(new SpinnerNumberModel(10,1,1500,1));
        timeStepSize.setModel(new SpinnerNumberModel(0.1,0.01,500,0.01));
        sourcePower.setModel(new SpinnerNumberModel(1,0.1,500,0.1));

        for (ModelType type : ModelType.values()) {
            modelType.addItem(type);
        }

        for (CoagulationFactor factor : CoagulationFactor.values()) {
            coagulationFactor.addItem(factor);
        }


    }
}
